package com.coder4j.controller;

import cn.hutool.json.JSONObject;
import com.coder4j.entity.SDisplayInterfaceEntity;
import com.coder4j.service.SDisplayInterfaceService;
import com.coder4j.vo.MenuData;
import com.coder4j.vo.SDisplayInterfaceQuery;
import com.coder4j.vo.SDisplayInterfaceVO;
import com.coder4j.starter.mybatis.BasePage;
import com.coder4j.starter.web.R;
import com.coder4j.utils.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 显示界面
 * @author keller
 * @date 2025-03-18 16:22:25
 */
@Slf4j
@RestController
@RequestMapping("/sDisplayInterface")
public class SDisplayInterfaceController {
    @Resource
    private SDisplayInterfaceService service;

    @Resource
    private HttpServletResponse response;

    /**
     * 按ID查询显示界面
     * @param id SDisplayInterface.id
     * @return 显示界面对象
     */
    @GetMapping("/getById")
    public R<SDisplayInterfaceVO> getById( Integer id){

        return R.success(service.baseGetVOById(id));
    }

    @GetMapping("/getMenuData")
    public R<List<MenuData>> getMenuData(){
        return R.success(service.getMenuData());
    }


    /**
     * 保存显示界面
     * 有 id 字段，更新；否则新增
     * @param sDisplayInterface SDisplayInterface对象
     * @return SDisplayInterface对象
     */
    @PostMapping("/save")
    public R save(@RequestBody SDisplayInterfaceVO sDisplayInterface){
        service.baseSaveVO(sDisplayInterface);
        return R.success();
    }

    /**
     * 查询列表
     * @param query 查询条件
     * @return 数据列表
     */
    @PostMapping("/page")
    public R<BasePage<SDisplayInterfaceVO>> getList(@RequestBody SDisplayInterfaceQuery query){
        if(query == null){
            query = new SDisplayInterfaceQuery();
        }
        return R.success(service.baseQueryVOPage(query));
    }

    /**
     * 删除显示界面
     * 如果Entity继承了 BaseSoftDeleteEntity，使用逻辑删除；否则，使用物理删除
     * @param id SDisplayInterface.id
     * @return 删除的数据
     */
    @PostMapping("/deleteById")
    public R deleteById( Integer id){
        service.baseDeleteById(id);
        return R.success();
    }

    @PostMapping("/add")
    public R add(@RequestBody JSONObject jsonObject){
        service.add(jsonObject);
        return R.success();
    }

    @GetMapping("/getOne")
    public R getOne(Integer id){
        JSONObject josn  = service.getOne(id);
        return R.success(josn);
    }

    @GetMapping("/opList")
    public R opList(){
        Object o = service.opList();
        return R.success(o);
    }
}
